#pragma once

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>

#include "Input.hpp"
#include "../Map/Map.hpp"
#include "../Entity/Player.hpp"

/**
\class Game
\author Plomeg
\date Mar. 15th 2013
\version 0.2
\brief Encapsulates the whole program, yet very simplified. Not ready for use.
**/

class Game
{
public:
	~Game();

	static Game* Instance(){if(!m_inst)m_inst = new Game;return m_inst;}

	sf::RenderWindow& Window(){return m_window;}
	/**
	\brief Configures the program and launches the main loop.
	\return The return value of the program.
	**/
	int launch();

	/**
	\brief Return the Input managed by Game.
	\return The Input.
	The fonction is const for only Game should modify this instance.
	**/
	const Input& getInput() const;
	bool isDebug() const {return m_debug;}

	/**
	\brief Return the Map.
	\return The Map.
	**/
	Map& getMap();

private:
	Game();
	bool m_debug;
	static Game* m_inst;
	sf::RenderWindow m_window;
	float m_step;
	bool m_running;
	Input m_input;
	Map m_map;
	unsigned int m_nextMap;
	sf::Vector2f m_destination;
	int m_transition; //used to change maps after some time, -1 if no transition
	sf::RectangleShape m_shade;
	sf::View m_view;
	Player* m_player;

	/**
	\brief The main loop.
	Works in this order : calcultate physics & stuff, manage events, draw, wait next frame.
	**/
	void mainLoop();

	/**
	\brief Sort events from the window.
	**/
	void sortEvents();

	/**
	\brief Update all the objects.
	**/
	void update();
	void setView();

	/**
	\brief Move objects and collisions
	**/
	void updateHUD();

	/**
	\brief Draw all the game.
	**/
	void draw();
};
